package cn.edu.scau.cmi.liangzijian.adapter.studentSortAdapter;

import java.util.ArrayList;
import java.util.List;

import cn.edu.scau.cmi.liangzijian.adapter.SortUtil;
import cn.edu.scau.cmi.liangzijian.adapter.Sortable;
import cn.edu.scau.cmi.liangzijian.adapter.Student;

public class SortStudentAdapterOfObject implements Sortable {
	
	private SortUtil sortUtil = new SortUtil();
	
	public List<Integer> sortInt(List<Integer> intList) {
		return sortUtil.sortInt(intList);
	}
	
	@Override
	public List<Student> sortStudent(List<Student> students) {
		List<Integer> intList = new ArrayList<Integer>();
		for(Student student : students) {
			intList.add(student.getId());
		}
		
		intList = sortInt(intList);
			
		List<Student> tmpStudents = new ArrayList<Student>(students);
		
		students.clear();
		for(Integer i : intList) {
			for(Student student : tmpStudents) {
				if(i == student.getId()) {
					students.add(student);
					break;
				}
			}
		}
		
		return students;
	}
}
